import Vue from 'vue'
import Router from 'vue-router'

import store from '../store'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'
// import Layout2 from '../views/layout/Layout2'

/**
 * hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
 *                                if not set alwaysShow, only more than one route under the children
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
 **/
export const constantRouterMap = [
  { path: '/monitor/overview/list', component: () => import('@/views/login/realtimeList'), hidden: true },
  { path: '/homeoverview', component: () => import('@/views/homeOverview/index'), hidden: true },
  { path: '/404', component: () => import('@/views/404'), hidden: true },
  {
    path: '/projectList',
    component: Layout,
    name: 'projectList',
    hidden: true,
    children: [{
      path: '/projectList',
      component: () => import('@/views/dashboard/projectList')
    }]
  },
  {
    path: '/map',
    component: Layout,
    name: 'projectList',
    hidden: true,
    children: [{
      path: '/map',
      component: () => import('@/views/dashboard/index')
    }]
  },
  // {
  //   path: '/messageCenter',
  //   component: Layout,
  //   name: 'messageCenter',
  //   meta: { title: '信息中心', icon: 'form' },
  //   alwaysShow: true,
  //   children: [{
  //     path: '/messageCenter/stationMessage',
  //     component: () => import('@/views/messageCenter/stationMessage'),
  //     meta: { title: '站内信息', icon: '' }
  //   }]
  // },
  {
    path: '/basicInfo/index',
    component: Layout,
    children: [
      {
        path: '/basicInfo/index',
        name: 'realTime',
        component: () => import('@/views/userMessage/basicInfo/index'),
        meta: { title: '账号管理', icon: 'form' }
      }
    ]
  },
  {
    path: '/basicInfo/updatepwd',
    component: Layout,
    children: [
      {
        path: '/basicInfo/updatepwd',
        name: 'updatePwd',
        component: () => import('@/views/userMessage/updatePwd'),
        meta: { title: '修改密码', icon: 'form' }
      }
    ]
  },
  {
    path: '/monitor/homepage/grab',
    component: Layout,
    redirect: '/monitor/homepage/grab',
    children: [
      {
        path: '/monitor/homepage/grab',
        name: 'realTime',
        component: () => import('@/views/realTime/index'),
        meta: { title: '实时监测', icon: 'form' }
      }
    ]
  },
  {
    path: '/',
    component: () => import('@/views/homeOverview/index'),
    redirect: '/monitor/console',
    hidden: true,
    children: [
      {
        path: '/monitor/console',
        name: 'realTimeconsole',
        component: () => import('@/views/homeOverview/index'),
        meta: { title: '控制台', icon: 'form' }
      }
    ]
  },
  {
    path: '/monitor',
    component: Layout,
    redirect: '/monitor/console',
    children: [
      {
        path: '/monitor',
        name: 'mapInfo',
        component: () => import('@/views/controlStation/mapInfo'),
        meta: { title: '控制台', icon: 'form' }
      }
    ]
  },
  {
    path: '/ComprehensiveMore',
    component: Layout,
    children: [
      {
        path: '/ComprehensiveMore',
        name: 'ComprehensiveMore',
        component: () => import('@/views/controlStation/ComprehensiveMore'),
        meta: { title: '综合信息', icon: 'form' }
      }
    ]
  },
  {
    path: '/controlStation',
    component: Layout,
    children: [
      {
        path: '/controlStation',
        name: 'controlStation',
        component: () => import('@/views/controlStation/index'),
        meta: { title: '每日摘要', icon: 'form' }
      }
    ]
  },
  {
    path: '/controlStation/detailedInformation',
    component: Layout,
    children: [
      {
        path: '/controlStation/detailedInformation',
        name: 'detailedInformation',
        component: () => import('@/views/controlStation/detailedInformation'),
        meta: { title: '详细信息', icon: 'form' }
      }
    ]
  },
  {
    path: '/detectionInfo',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/realTime/detectionInfo',
        name: 'detectionInfo',
        component: () => import('@/views/realTime/detectionInfo'),
        meta: { title: '监测信息', icon: 'form' }
      }
    ]
  },
  {
    path: '/viewEquip',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/monitor/equip',
        name: 'viewEquip',
        component: () => import('@/views/realTime/viewEquip'),
        meta: { title: '设备信息', icon: 'form' }
      }
    ]
  },
  {
    path: '/updateEquip',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/update',
        name: 'viewEquip',
        component: () => import('@/views/realTime/updateEquip'),
        meta: { title: '编辑设备信息', icon: 'form' }
      }
    ]
  },
  {
    path: '/monitor/today',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/monitor/today',
        name: 'todayData',
        component: () => import('@/views/realTime/todayData'),
        meta: { title: '今日数据', icon: 'form' }
      }
    ]
  },
  {
    path: '/message',
    component: Layout,
    children: [
      {
        path: '/message',
        name: 'MessageCenter',
        component: () => import('@/views/messageCenter/index'),
        meta: { title: '信息中心', icon: '' }
      },
      {
        path: '/message/history',
        name: 'MessageCenterHistory',
        component: () => import('@/views/messageCenter/historyIndex'),
        meta: { title: '历史数据', icon: '' }
      }
    ]
  },
  // {
  //   path: '/message',
  //   component: Layout,
  //   name: 'MmessageCenter',
  //   meta: { title: '消息', icon: 'form' },
  //   alwaysShow: true,
  //   children: [{
  //     path: '/message/center',
  //     component: Layout2,
  //     meta: { title: '信息中心', icon: '' },
  //     children: [{
  //       path: '/message/station',
  //       component: () => import('@/views/messageCenter/stationMessage'),
  //       meta: { title: '站内信息', icon: '' },
  //       hidden: true
  //     }, {
  //       path: '/message/notice',
  //       component: () => import('@/views/messageCenter/notification'),
  //       meta: { title: '通知公告', icon: '' },
  //       hidden: true
  //     }, {
  //       path: '/message/event',
  //       component: () => import('@/views/messageCenter/alarmMessage'),
  //       meta: { title: '告警信息', icon: '' },
  //       hidden: true
  //     }, {
  //       path: '/message/warning',
  //       component: () => import('@/views/messageCenter/warningMessage'),
  //       meta: { title: '预警信息', icon: '' },
  //       hidden: true
  //     }]
  //   }]
  // },
  {
    path: '/nested',
    redirect: '/nested/menu1',
    component: Layout,
    children: [
      {
        path: '/monitor/curve',
        name: 'nested',
        component: () => import('@/views/nested/menu1/index'),
        meta: { title: '参数曲线', icon: 'form' }
      }
    ]
  },
  {
    path: '/queryInfo',
    component: Layout,
    children: [
      {
        path: '/monitor/history',
        name: 'historicalqueryInfo',
        component: () => import('@/views/historicalQuery/queryInfo'),
        meta: { title: '历史查询', icon: 'form' }
      }
    ]
  },
  {
    path: '/configManage',
    component: Layout,
    children: [
      {
        path: '/monitor/config',
        name: 'configInfo',
        component: () => import('@/views/configurationManagement/index'),
        meta: { title: '配置管理', icon: 'form' }
      }
    ]
  },
  {
    path: '/equipManagement',
    component: Layout,
    children: [
      {
        path: '/monitor/iots',
        name: 'equipManagement',
        component: () => import('@/views/newEquipment/pandectTableIndex'),
        meta: { title: '设备管理', icon: 'form' }
      },
      {
        path: '/equipManagement/components/equipdetail',
        name: 'equipdetail',
        component: () => import('@/views/equipManagement/components/equipdetail'),
        meta: { title: '查看设备', icon: 'form' },
        hidden: true
      },
      {
        path: '/equipManagement/components/redactequip',
        name: 'redactequip',
        component: () => import('@/views/equipManagement/components/redactequip'),
        meta: { title: '编辑设备', icon: 'form' },
        hidden: true
      },
      {
        path: '/equipManagement/components/equipcontrast',
        name: 'equipcontrast',
        component: () => import('@/views/equipManagement/components/equipcontrast'),
        meta: { title: '设备对比', icon: 'form' },
        hidden: true
      },
      {
        path: '/equipManagement/components/equipoverview',
        name: 'equipoverview',
        component: () => import('@/views/newEquipment/index.vue'),
        meta: { title: '设备总览', icon: 'form' },
        hidden: true
      },
      {
        // path: '/equipManagement/components/equipPandect',
        path: '/monitor/iots',
        name: 'equipPandect',
        component: () => import('@/views/newEquipment/pandectTableIndex'),
        meta: { title: '设备列表总览', icon: 'form' },
        hidden: true
      },
      {
        path: '/equipManagement/components/contrastTable',
        name: 'contrastTable',
        component: () => import('@/views/newEquipment/components/contrastTable'),
        meta: { title: '设备列表总览-对比', icon: 'form' },
        hidden: true
      }
    ]
  },
  {
    path: '/MequipManagement',
    component: Layout,
    children: [
      {
        path: '/monitor/system/iots',
        name: 'MequipManagement',
        component: () => import('@/views/managementSide/MequipManagement/index'),
        meta: { title: 'M设备管理', icon: 'form' }
      },
      {
        path: '/MequipManagement/components/Maddequip',
        name: 'Maddequip',
        component: () => import('@/views/managementSide/MequipManagement/components/Maddequip'),
        meta: { title: 'M新增设备', icon: 'form' },
        hidden: true
      },
      {
        path: '/MequipManagement/components/Mequipdetail',
        name: 'Mequipdetail',
        component: () => import('@/views/managementSide/MequipManagement/components/Mequipdetail'),
        meta: { title: 'M查看设备', icon: 'form' },
        hidden: true
      },
      {
        path: '/MequipManagement/components/Mredactequip',
        name: 'Mredactequip',
        component: () => import('@/views/managementSide/MequipManagement/components/Mredactequip'),
        meta: { title: 'M编辑设备', icon: 'form' },
        hidden: true
      },
      {
        path: '/MequipManagement/components/Mequipcontrast',
        name: 'Mequipcontrast',
        component: () => import('@/views/managementSide/MequipManagement/components/Mequipcontrast'),
        meta: { title: 'M设备对比', icon: 'form' },
        hidden: true
      }
    ]
  },
  {
    path: '/monitor/update',
    component: Layout,
    children: [
      {
        path: '/monitor/update',
        name: 'remoteUpdate',
        component: () => import('@/views/remoteUpdate/index'),
        meta: { title: '远程更新', icon: 'form' }
      }
    ]
  },
  {
    path: '/monitor/log',
    component: Layout,
    children: [
      {
        path: '/monitor/log',
        name: 'operationlogIndex',
        component: () => import('@/views/operationlog/index'),
        meta: { title: '操作日志', icon: 'form' }
      }
    ]
  },
  {
    path: '/monitor/system/log',
    component: Layout,
    children: [
      {
        path: '/monitor/system/log',
        name: 'MoperationlogIndex',
        component: () => import('@/views/managementSide/mOperationlog/index'),
        meta: { title: '操作日志', icon: 'form' }
      }
    ]
  },
  {
    path: '/southbound',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/southbound/real',
        name: 'southboundReal',
        component: () => import('@/views/southbound/real')
      }
    ]
  },
  {
    path: '/monitor/etl',
    component: Layout,
    children: [
      {
        path: '/monitor/etl',
        name: 'etlIndex',
        component: () => import('@/views/configurationETL/index'),
        meta: { title: 'ETL', icon: 'form' }
      },
      {
        path: '/configurationETL/component/addETL',
        name: 'addETL',
        component: () => import('@/views/configurationETL/component/addETL'),
        meta: { title: '新增ETL', icon: 'form' },
        hidden: true
      },
      {
        path: '/configurationETL/component/checkETL',
        name: 'checkETL',
        component: () => import('@/views/configurationETL/component/checkETL'),
        meta: { title: 'ETL策略详情', icon: 'form' },
        hidden: true
      },
      {
        path: '/configurationETL/component/editETL',
        name: 'editETL',
        component: () => import('@/views/configurationETL/component/editETL'),
        meta: { title: '编辑策略', icon: 'form' },
        hidden: true
      }
    ]
  },
  // 以下菜单信息是用户管理端的相关配置，若是客户端路径配在上方
  {
    path: '/HeartbeatManagement',
    component: Layout,
    children: [
      {
        path: '/monitor/system/heartbeat',
        name: 'heartbeatManagementIndex',
        component: () => import('@/views/managementSide/HeartbeatManagement/index'),
        meta: { title: '心跳管理', icon: 'form' }
      }
    ]
  },
  {
    path: '/SendMassage',
    component: Layout,
    children: [
      {
        path: '/monitor/system/send/config',
        name: 'queryInfos',
        component: () => import('@/views/managementSide/SendMassage/index'),
        meta: { title: '信息发送配置', icon: 'form' }
      }
    ]
  },
  {
    path: '/recordMassage',
    component: Layout,
    children: [
      {
        path: '/monitor/system/send/list',
        name: 'queryMassageInfo',
        component: () => import('@/views/managementSide/recordMassage/index'),
        meta: { title: '信息发送记录', icon: 'form' }
      }
    ]
  },
  {
    path: '/ptcManage',
    component: Layout,
    children: [
      {
        path: '/monitor/system/protocol',
        name: 'ptcManageInfo',
        component: () => import('@/views/managementSide/protocolManage/index'),
        meta: { title: '协议库管理', icon: 'form' }
      }
    ]
  },
  {
    path: '/monitor/system/reports',
    component: Layout,
    children: [
      {
        path: '/monitor/system/reports',
        name: 'Mreports',
        component: () => import('@/views/managementSide/Mreports/index'),
        meta: { title: '报表', icon: 'form' }
      }
    ]
  },
  {
    path: '/monitor/reports',
    component: Layout,
    children: [
      {
        path: '/monitor/reports',
        name: 'reports',
        component: () => import('@/views/reports/index'),
        meta: { title: '报表', icon: 'form' }
      }
    ]
  },
  {
    path: '/monitor/calendar',
    component: Layout,
    children: [
      {
        path: '/monitor/calendar',
        name: 'calendar',
        component: () => import('@/views/calendar/index'),
        meta: { title: '日历', icon: 'form' }
      }
    ]
  },
  {
    path: '/WBgate',
    component: Layout,
    children: [
      {
        path: '/monitor/system/iot',
        name: 'WBgateInfo',
        component: () => import('@/views/managementSide/WBgateway/index'),
        meta: { title: '物联网管管理', icon: 'form' }
      }
    ]
  },
  {
    path: '/MsiteAdmin',
    component: Layout,
    children: [
      {
        path: '/monitor/system/station',
        name: 'MsiteAdmin',
        component: () => import('@/views/managementSide/mSiteAdmin/index'),
        meta: { title: 'M站点管理', icon: 'form' }
      },
      {
        path: '/managementSide/mSiteAdmin/addSite',
        name: 'AddSite',
        component: () => import('@/views/managementSide/mSiteAdmin/addSite'),
        meta: { title: 'M新增站点', icon: '' },
        hidden: true
      },
      {
        path: '/managementSide/mSiteAdmin/editSite',
        name: 'EditSite',
        component: () => import('@/views/managementSide/mSiteAdmin/editSite'),
        meta: { title: 'M编辑站点', icon: '' },
        hidden: true
      },
      {
        path: '/managementSide/mSiteAdmin/lookSite',
        name: 'LookSite',
        component: () => import('@/views/managementSide/mSiteAdmin/lookSite'),
        meta: { title: 'M查看站点', icon: '' },
        hidden: true
      },
      {
        path: '/managementSide/mSiteAdmin/lookEquip',
        name: 'lookEquip',
        component: () => import('@/views/managementSide/mSiteAdmin/lookEquip'),
        meta: { title: 'M查看设备信息', icon: '' },
        hidden: true
      },
      {
        path: '/managementSide/mSiteAdmin/lookInternet',
        name: 'lookInternet',
        component: () => import('@/views/managementSide/mSiteAdmin/lookInternet.vue'),
        meta: { title: 'M查看物联网关信息', icon: '' },
        hidden: true
      },
      {
        path: '/monitor/system/project',
        name: 'mProjectManagement',
        component: () => import('@/views/managementSide/mProjectManagement/index'),
        meta: { title: 'M项目管理', icon: 'form' }
      },
      {
        path: '/managementSide/mProjectManagement/addProject',
        name: 'addProject',
        component: () => import('@/views/managementSide/mProjectManagement/addProject'),
        meta: { title: 'M新增项目', icon: '' },
        hidden: true
      },
      {
        path: '/managementSide/mProjectManagement/editProject',
        name: 'editProject',
        component: () => import('@/views/managementSide/mProjectManagement/editProject'),
        meta: { title: 'M编辑项目', icon: '' },
        hidden: true
      },
      {
        path: '/managementSide/mProjectManagement/lookProject',
        name: 'lookProject',
        component: () => import('@/views/managementSide/mProjectManagement/lookProject'),
        meta: { title: 'M查看项目', icon: '' },
        hidden: true
      },
      {
        path: '/managementSide/mSiteAdmin/addSite',
        name: 'MAddSite',
        component: () => import('@/views/managementSide/mSiteAdmin/addSite'),
        meta: { title: 'M新增站点', icon: '' },
        hidden: true
      },
      {
        path: '/managementSide/mSiteAdmin/editSite',
        name: 'MEditSite',
        component: () => import('@/views/managementSide/mSiteAdmin/editSite'),
        meta: { title: 'M编辑站点', icon: '' },
        hidden: true
      },
      {
        path: '/managementSide/mSiteAdmin/lookSite',
        name: 'MLookSite',
        component: () => import('@/views/managementSide/mSiteAdmin/lookSite'),
        meta: { title: 'M查看站点', icon: '' },
        hidden: true
      }
    ]
  },
  {
    path: '/configurationAndQuery',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/managementSide/mSiteAdmin/configurationAndQuery/index',
        name: 'configurationAndQuery',
        component: () => import('@/views/managementSide/mSiteAdmin/configurationAndQuery/index'),
        meta: { title: 'M站点（配置与查询）', icon: 'form' }
      }
    ]
  },
  {
    path: '/monitor/system/components',
    component: Layout,
    children: [
      {
        path: '/monitor/system/components/reminder',
        name: 'MexpirationReminding',
        component: () => import('@/views/managementSide/mComponents/expirationReminding'),
        meta: { title: '到期提醒总览', icon: 'form' }
      },
      {
        path: '/monitor/system/components/records',
        name: 'MreplacementParts',
        component: () => import('@/views/managementSide/mComponents/replacementParts'),
        meta: { title: '配件更换记录', icon: 'form' }
      },
      {
        path: '/monitor/system/components/strateygs',
        name: 'MremindingStrategy',
        component: () => import('@/views/managementSide/mComponents/remindingStrategy'),
        meta: { title: '提醒策略配置', icon: 'form' }
      },
      {
        path: '/monitor/system/components/strateygsAdd',
        name: 'MreplacementAdd',
        component: () => import('@/views/managementSide/mComponents/components/remindAdd'),
        meta: { title: '新增提醒策略', icon: 'form' },
        hidden: true
      },
      {
        path: '/monitor/system/components/strateygsLook',
        name: 'MreplacementLook',
        component: () => import('@/views/managementSide/mComponents/components/remindLook'),
        meta: { title: '查看提醒策略', icon: 'form' },
        hidden: true
      },
      {
        path: '/monitor/system/components/strateygsEdit',
        name: 'MreplacementEdit',
        component: () => import('@/views/managementSide/mComponents/components/remindEdit'),
        meta: { title: '编辑提醒策略', icon: 'form' },
        hidden: true
      },
      {
        path: '/monitor/system/components/cycleLook',
        name: 'McycleLook',
        component: () => import('@/views/managementSide/mComponents/components/cycleLook'),
        meta: { title: '周期提醒详情', icon: 'form' },
        hidden: true
      },
      {
        path: '/monitor/system/components/expirationLook',
        name: 'MexpirationLook',
        component: () => import('@/views/managementSide/mComponents/components/expirationLook'),
        meta: { title: '到期提醒详情', icon: 'form' },
        hidden: true
      },
      {
        path: '/monitor/system/components/recordsAdd',
        name: 'MrecordsAdd',
        component: () => import('@/views/managementSide/mComponents/components/replaceAdd'),
        meta: { title: '配件更换记录新增', icon: 'form' },
        hidden: true
      },
      {
        path: '/monitor/system/components/recordsLook',
        name: 'MrecordsLook',
        component: () => import('@/views/managementSide/mComponents/components/replaceLook'),
        meta: { title: '配件更换记录查看', icon: 'form' },
        hidden: true
      },
      {
        path: '/monitor/system/components/replaceEdit',
        name: 'MreplaceEdit',
        component: () => import('@/views/managementSide/mComponents/components/replaceEdit'),
        meta: { title: '配件更换记录编辑', icon: 'form' },
        hidden: true
      },
      {
        path: '/monitor/system/components/replaceFinish',
        name: 'MreplaceFinish',
        component: () => import('@/views/managementSide/mComponents/components/replaceFinish'),
        meta: { title: '配件更换记录完成', icon: 'form' },
        hidden: true
      }
    ]
  },
  {
    path: '/monitor/components',
    component: Layout,
    children: [
      {
        path: '/monitor/components/reminder',
        name: 'expirationReminding',
        component: () => import('@/views/componentsModule/expirationReminding'),
        meta: { title: '到期提醒总览', icon: 'form' }
      },
      {
        path: '/monitor/components/records',
        name: 'remindingStrategy',
        component: () => import('@/views/componentsModule/replacementParts'),
        meta: { title: '配件更换记录', icon: 'form' }
      },
      {
        path: '/monitor/components/strateygs',
        name: 'replacementParts',
        component: () => import('@/views/componentsModule/remindingStrategy'),
        meta: { title: '提醒策略配置', icon: 'form' }
      },
      {
        path: '/monitor/components/strateygsAdd',
        name: 'replacementAdd',
        component: () => import('@/views/componentsModule/components/remindAdd'),
        meta: { title: '新增提醒策略', icon: 'form' },
        hidden: true
      },
      {
        path: '/monitor/components/strateygsLook',
        name: 'replacementLook',
        component: () => import('@/views/componentsModule/components/remindLook'),
        meta: { title: '查看提醒策略', icon: 'form' },
        hidden: true
      },
      {
        path: '/monitor/components/strateygsEdit',
        name: 'replacementEdit',
        component: () => import('@/views/componentsModule/components/remindEdit'),
        meta: { title: '编辑提醒策略', icon: 'form' },
        hidden: true
      },
      {
        path: '/monitor/components/cycleLook',
        name: 'cycleLook',
        component: () => import('@/views/componentsModule/components/cycleLook'),
        meta: { title: '周期提醒详情', icon: 'form' },
        hidden: true
      },
      {
        path: '/monitor/components/expirationLook',
        name: 'expirationLook',
        component: () => import('@/views/componentsModule/components/expirationLook'),
        meta: { title: '到期提醒详情', icon: 'form' },
        hidden: true
      },
      {
        path: '/monitor/components/recordsAdd',
        name: 'recordsAdd',
        component: () => import('@/views/componentsModule/components/replaceAdd'),
        meta: { title: '配件更换记录新增', icon: 'form' },
        hidden: true
      },
      {
        path: '/monitor/components/recordsLook',
        name: 'recordsLook',
        component: () => import('@/views/componentsModule/components/replaceLook'),
        meta: { title: '配件更换记录查看', icon: 'form' },
        hidden: true
      },
      {
        path: '/monitor/components/replaceEdit',
        name: 'replaceEdit',
        component: () => import('@/views/componentsModule/components/replaceEdit'),
        meta: { title: '配件更换记录编辑', icon: 'form' },
        hidden: true
      },
      {
        path: '/monitor/components/replaceFinish',
        name: 'replaceFinish',
        component: () => import('@/views/componentsModule/components/replaceFinish'),
        meta: { title: '配件更换记录完成', icon: 'form' },
        hidden: true
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]

const router = new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

function getIrem(path, item) {
  if (item) {
    if (item.url === path) {
      return item
    } else if (item.children) {
      // item.children.forEach((e) => {
      //   console.log('let e', e)
      //   return getIrem(path, e)
      // })
      for (const key in item.children) {
        // console.log('let key', key)
        let irem = getIrem(path, item.children[key])
        if (irem) {
          return irem
        }
      }
    }
  }
}

router.afterEach((to, from) => {
  console.log('to.url', to)
  if (store.getters.authen) {
    let item = store.getters.authen.find(function(value, index, arr) {
      // console.log('value', value)
      if (value.children) {
        let item2 = value.children.find(function(value2, index, arr) {
          return value2.url === to.path
        })
        if (item2) {
          console.log('value2', item2)
          return value
        }
      }
      return value.url === to.path
    })
    if (item) {
      console.log('item', item)
      store.commit('authen_select_item', item)
    }
  }
})

router.beforeEach((to, from, next) => {
  let strings = window.location.href.split('?')
  if (strings.length > 1) {
    let access_token = getParameterByName('access_token', strings[1])
    if (access_token) {
      // store.dispatch('login', { 'access_token': access_token, 'url': strings[0] }) // 从哪里退出就回到哪里
      store.dispatch('login', { 'access_token': access_token, 'url': '/' }) // 修改无论从哪里退出进入的都是首页
    }
  }
  if (!store.getters.access_token) {
    window.location.href = process.env.SERVER_URL_4A_VUE + '?callbackUrl=' + encodeURIComponent(window.location.href)
  }
  let irem
  for (let i = 0; i < store.getters.authen.length; i++) {
    irem = getIrem(to.path, store.getters.authen[i])
    // if (i === 2) {
    //   debugger
    // }
    if (irem) {
      break
    }
  }
  if (irem) {
    next()
  } else {
    // console.log('22222222222', 22222222222)
    // 没有权限跳转到首页
    if (store.getters.authen) {
      console.log('store.getters.authen', store.getters.authen)
      console.log('store.getters.authen[0].url', store.getters.authen[0].url)
      // next(store.getters.authen[0].url)
      next()
    } else {
      next()
    }
  }
  // // 处理面包屑
  // let breadcrumbList = store.getters.breadcrumbList || []
  // if (breadcrumbList.length > 0) {
  //   if (breadcrumbList.length >= 2) {
  //     if (to.path === breadcrumbList[breadcrumbList.length - 2].path) {
  //       store.commit('REMOVE_BREADCRUMB')
  //     } else if (to.path === breadcrumbList[breadcrumbList.length - 1].path) {
  //       // console.log('同一个页面')
  //     } else {
  //       store.commit('PUSH_BREADCRUMB', to)
  //     }
  //   } else {
  //     store.commit('PUSH_BREADCRUMB', to)
  //   }
  // }
})

/**
 * 获取参数
 * @param paramName
 * @returns {*}
 */
function getParameterByName(paramName, argsStr) {
  let args = []
  if (argsStr) {
    let argsStrs = argsStr.split('#')
    if (argsStrs.length > 1) {
      argsStr = argsStrs[0]
    }
  }
  if (argsStr && argsStr.length > 0) {
    // 多参数
    var nameValueArr = argsStr.split('&')
    for (var i = 0; i < nameValueArr.length; i++) {
      var pos = nameValueArr[i].indexOf('=')
      if (pos === -1) continue // 如果没有找到就跳过
      var argName = nameValueArr[i].substring(0, pos) // 提取name
      var argVal = nameValueArr[i].substring(pos + 1) // 提取value
      args[argName] = unescape(argVal)
    }
    return args[paramName]
  }
}

export default router
